#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main() {
	int n;
	cin >> n;
	while (n--) {
		string s[3];
		cin >> s[0] >> s[1] >> s[2];

		char ans;
		vector<int> vis('Z');
		vis['A'] = vis['B'] = vis['C'] = 3;

		for (int k = 0; k < 3; k++) {

			for (int i = 0; i < 3; i++) {
				if (s[k][i] == 'A')
					vis['A']--;
				else if (s[k][i] == 'B')
					vis['B']--;
				else if (s[k][i] == 'C')
					vis['C']--;
			}
		}
		ans = max_element(vis.begin(), vis.end()) - vis.begin();
		cout << ans << endl;
	}
	return 0;
}
